function program()
    % updateInterval = 1000;     % The update interval in ms.

    % Create an array of roads here (edges of the graph)
    r = road(1, 0, 1000, 20, 15);
    addCar(r, 'Car 1', true);
    addCar(r, 'Car 2', true);
    addTruck(r, 'Truck 1', true);
    addTruck(r, 'Truck 2', true);
    
    for i = 1:100
        update(r);
    end
end

function update(roads)
    for i = 1:length(roads)
        road = roads(i);
        % Not sure if null has a meaning in matlab also, i don't what the first car is supposed to do
        road.firstCar.Data.velocity = road.maxSpeedCars;
        road.firstCar.Data.drive([]);
        
        pCar = road.firstCar;
        cCar = pCar.Next;
        
        while ~isempty(cCar)
            cCar.Data.drive(pCar.Data);           % Update the car's velocity and position based on the state of the car in front of it
            pCar = cCar;
            cCar = cCar.Next;
        end
    end
end

function addCar(road, name, initial)
    length = 2.5;                       % Length of the car
    dVel = road.maxSpeedCars;           % Desired velocity in m/s
    timeHead = 1.5;                     % Recommended time headway
    minSpace = 2;                       % Recommended gap between two vehicles
    dAccel = 0.3;                       % Desired acceleration in m/s^2
    decel = 3;                          % Comfortable deceleration rate
    
    road.addCar(car(length, dVel, minSpace, timeHead, dAccel, decel, name), initial);
end

function addTruck(road, name, initial)
    length = 10;                        % Length of the car
    dVel = road.maxSpeedTrucks;         % Desired velocity in m/s
    timeHead = 1.7;                     % Recommended time headway
    minSpace = 2;                       % Recommended gap between two vehicles
    dAccel = 0.3;                       % Desired acceleration in m/s^2
    decel = 2;                          % Comfortable deceleration rate
    
    road.addCar(car(length, dVel, minSpace, timeHead, dAccel, decel, name), initial);
end

